<?php
/*
 * @Author: your name
 * @Date: 2021-11-09 10:27:12
 * @LastEditTime: 2022-01-03 23:08:10
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \property\app\Http\Middleware\SetHeader.php
 */

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class SetHeader
{

    // private $session_name = 'adminApi';
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        //  if(!isset($_POST['HTTP_SERVER'])){   //不是swoole请求时设置跨域
        //     header("access-control-allow-headers: *");
        //     header("access-control-allow-methods: GET, POST, PUT, DELETE, HEAD, OPTIONS");
        //     header("access-control-allow-credentials: true");
        //     header("access-control-allow-origin: *");
        //     header('X-Powered-By: WAF/2.0');
        //  }
      

        // if(!isset($_SESSION)){                               //如果没有则设置session
        //     session_set_cookie_params(['lifetime'=>time() + 99 * 365 * 24 * 3600, 'path'=>'/',
        //     // 'secure'=>true,'HttpOnly'=>true
        //      ] ) ; 
        //     session_name($this->session_name);
        //     session_start();
        // }
        // if(isset($_POST['HTTP_SERVER_REQUEST'])){
        //     $cookie =  $_POST['HTTP_SERVER_REQUEST']->cookie;
        //     if(isset($cookie[$this->session_name])){
        //         echo $cookie[$this->session_name];
        //       $_POST['HTTP_SERVER']->cookie($this->session_name,$cookie[$this->session_name],time() + 99 * 365 * 24 * 3600,'/');
        //     }else{
        //         $_POST['HTTP_SERVER']->cookie(session_name(),session_id(),time() + 99 * 365 * 24 * 3600,'/');
        //     }
        //  }
//         session.use_cookies表示是否开始基于cookies的session会话
// session.use_only_cookies 表示是否只开启基于cookies的session的会话方式

// 就是说如果session.use_trans_sid=1并且客户端浏览器禁止cookie的时候，达不到效果，就要注意session.use_only_cookies的值是否为0
        // $_SESSION['userInfo'] = 123;
        // var_dump($_SESSION);
        // header("Access-Control-Allow-Origin: *");

        // $headers = [
        //     'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
        //     'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin'
        // ];

        // $response = $next($request);
        // foreach($headers as $key => $value) 
        //     $response->header($key, $value);
        // return $response;
        return $next($request);
    }
}
